<?php
abstract class DataObject extends Object
{
    protected $model;

    public function DataObject($id = null)
    {
        $this->model = $this->GetModel();
        $this->LoadById($id);
    }

    protected function LoadById($id)
    {
        if (!$id) return;
        $item = $this->model->FindById($id);
        if ($item) $this->LoadData($item);
    }

    public function LoadData($array)
    {
        foreach ($array as $field => $value)
        {
            $field = String::Camelize($field);
            $this->$field = $value;
        }
    }

    protected function GetModel()
    {
        $get_instance = $this->GetModelClassName().'::GetInstance';
        return call_user_func($get_instance);
    }

    protected function GetModelClassName()
    {
        return $this->GetClassName().'Model';
    }
}
?>
